<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;

class ShippingAddress extends Model
{
	use HasDateTimeFormatter;
    protected $table = 'shipping_address';
    public $timestamps = false;

    const ShippingAddressCache = 'shippingaddress';
    const Expire = 3600 * 24 * 7;

    public static function getAdd($id = null){


        if (!Cache::has(self::ShippingAddressCache)) {
            $list = self::all()->toArray();
            Cache::put(self::ShippingAddressCache, $list, self::Expire);
        }
        $list = Cache::get(self::ShippingAddressCache);
        if ($id) {
            foreach ($list as $add) {
                if ($add['id'] == $id) {
                    return $add;
                }
            }
        } else {
            return $list;
        }
    }

}
